package com.geen.tuoke.utils.ext

import android.annotation.SuppressLint
import android.content.Context
import android.text.TextUtils
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import android.widget.Toast
import androidx.annotation.StringRes
import com.geen.tuoke.MyApplication
import com.geen.tuoke.R
import com.qmuiteam.qmui.util.QMUIDisplayHelper


fun toastShort(text: String) {
    toastTipsShort(text)

}
//    Toast.makeText(MyApplication.instance, text, Toast.LENGTH_SHORT).show()

fun toastLong(text: String) {
    toastTipsLong(text)
}
//    Toast.makeText(MyApplication.instance, text, Toast.LENGTH_LONG).show()



fun toastShort(@StringRes textId: Int) =
    toastShort(MyApplication.instance.getString(textId))


fun toastLong(@StringRes textId: Int) =
    toastLong(MyApplication.instance.getString(textId))

private fun showTips(
    context: Context?,
    tipsString: String?,
    duration: Int
) {
    if (TextUtils.isEmpty(tipsString)) {
        return
    }
    val t = Toast(context)
    t.setGravity(Gravity.CENTER, 0, 0)
    t.duration = duration
    val mInflater = LayoutInflater.from(context)
    @SuppressLint("InflateParams") val view: View =
        mInflater.inflate(R.layout.toast_tips_layout, null)
    val text = view.findViewById<TextView>(R.id.text_toast)
    text.text = tipsString
    view.minimumWidth = 9999
    view.minimumHeight = QMUIDisplayHelper.dp2px(context, 48)
    t.view = view
    t.show()
}

fun toastTipsShort(tipsString: String) {
    showTips(MyApplication.instance, tipsString, Toast.LENGTH_SHORT)
}

fun toastTipsLong(tipsString: String) {
    showTips(MyApplication.instance, tipsString, Toast.LENGTH_LONG)
}

